package com.filmbooks.presenter.detail;

import com.filmbooks.contract.detail.ZhihuDetailContract;
import com.filmbooks.model.detail.ZhihuDetailModel;
import com.filmbooks.model.home.bean.home.ZhihuDailyDetailBean;

import io.reactivex.functions.Consumer;

/**
 * Created by heshuxiang on 2018/3/7.
 * 描述：
 * 公司：盟将威
 * 作者：heshuxiang
 * 日期：2018/3/7.
 * 工程：FilmBooks
 * 包：com.filmbooks.presenter.detail
 */

public class ZhihuDeatilPresenter extends ZhihuDetailContract.ZhihuDetailPresenter {

    @Override
    public ZhihuDetailContract.IZhihuDetailModel getModel() {
        return ZhihuDetailModel.newInstance();
    }

    public static ZhihuDeatilPresenter newInstance() {
        return new ZhihuDeatilPresenter();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void loadDailyDetail(String id) {
        if (mIModel == null)
            return;
        mRxManager.register(mIModel.getDailyDetail(id).subscribe(new Consumer<ZhihuDailyDetailBean>() {
            @Override
            public void accept(ZhihuDailyDetailBean zhihuDailyDetailBean) throws Exception {
                if (mIView != null)
                    mIView.showDailyDetail(zhihuDailyDetailBean);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    mIView.showToast("网络异常");
                    mIView.showNetworkError();
                }
            }
        }));
    }
}